package com.zsw.proxy;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ClientHandler extends SimpleChannelInboundHandler<String> {
	
	private final Logger LOG = LoggerFactory.getLogger(this.getClass());
	
	public BlockingQueue<String> qu = new LinkedBlockingQueue<String>(1);
	
	private CountDownLatch lathc ;
	
	public ClientHandler(CountDownLatch c) {
		this.lathc = c;
	}
	@Override
	public void channelRead0(ChannelHandlerContext ctx, String body) throws Exception {
        qu.put(body);
        lathc.countDown();
	}
	@Override
	public void channelActive(ChannelHandlerContext ctx) {
		LOG.info("客户端连接服务器，开始发送数据……");
	}
	@Override
	public void channelInactive(ChannelHandlerContext ctx) throws Exception {
		super.channelInactive(ctx);
		LOG.info("客户端断开服务器");
	}
	public static void main(String[] args) {
		CountDownLatch latch = new CountDownLatch(100);
		long l = System.currentTimeMillis();
		while(latch.getCount() != 0){
			latch.countDown();
		}
		System.out.println(System.currentTimeMillis() - l);
	}
}
